<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Horizontal ScrollView</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>Example: Horizontal ScrollView</h1>

    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><div class="intro">
    <p>This example shows how to create a ScrollView widget which scrolls horizontally.</p>
</div>

<div class="example newwindow">
    <a href="scrollview-horiz-example.html" target="_blank" class="button">
        View Example in New Window
    </a>
</div>

<h2>A Horizontal ScrollView</h2>

<p>In this example, we'll create a ScrollView instance, which scrolls horizontally, as opposed to the vertically scrolling ScrollView we created in the <a href="scrollview.html">ScrollView With Scroll Indicator</a> example.</p>

<p>The code for the example is pretty much the same as the code for the <a href="scrollview.html">ScrollView With Scroll Indicator</a> example. The only difference is that instead of having a ScrollView with a fixed height (and content which overflows that height), we set up a ScrollView with a fixed width (and content which overflows that width).</p>

<h3>Modules Used</h3>

<p>Since we want to use the base ScrollView, along with the ScrollViewScrollbars plugin, we use the <code>scrollview</code> module as we did for the vertical ScrollView example:</p>

<pre class="code prettyprint">YUI().use(&#x27;scrollview&#x27;, function(Y) {
    ...
});</pre>


<h3>Instantiating The ScrollView Widget</h3>

<p>As with the vertical <a href="scrollview.html">ScrollView</a> example, we provide the markup for the ScrollView content on the page, as shown below:</p>

<pre class="code prettyprint">&lt;!-- Content with a width which would require scrolling --&gt;
&lt;div id=&quot;scrollview-content&quot; class=&quot;yui3-scrollview-loading&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;img src=&quot;...&quot;&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;img src=&quot;...&quot;&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;img src=&quot;...&quot;&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;img src=&quot;...&quot;&gt;&lt;&#x2F;li&gt;
    &lt;&#x2F;ul&gt;
&lt;&#x2F;div&gt;</pre>


<p>But this time, when we instantiate the ScrollView instance, we provide a fixed width, as opposed to a fixed height, for the widget.</p> 

<pre class="code prettyprint">&#x2F;&#x2F; Constraining the width, instead of the height for horizontal scrolling
var scrollView = new Y.ScrollView({
    id: &#x27;scrollview&#x27;,
    srcNode: &#x27;#scrollview-content&#x27;,
    width: 320,
    flick: {
        minDistance:10,
        minVelocity:0.3,
        axis: &quot;x&quot;
    }
});

scrollView.render();</pre>


<p>This causes the list content (which has inline-block applied to each LI by the scrollview CSS) to be wider than the ScrollView, forcing horizontal scrolling. The height of the ScrollView in this case is driven by the height of it's content. As with the ScrollView Base example, we constrain flick handling to a specific axis, in this case the "x" axis.</p>

<p>The important CSS for the example, which switches the LIs to layout horizontally, is shown below, along with some tweaks requires for IE 6 and 7 support:</p>

<pre class="code prettyprint">&#x2F;* To layout horizontal LIs *&#x2F;
#scrollview-content {
    white-space:nowrap;
}

#scrollview-content li {
    display:inline-block;
    background-color:#fff;
}

&#x2F;* For IE 6&#x2F;7 - needs inline block hack (and the background color mentioned above) *&#x2F;
#scrollview-content li {
    *display:inline;
    *zoom:1;
}</pre>


<p><strong>NOTE:</strong> In the initial ScrollView release (3.2.0), the above CSS to layout LIs horizontally was bundled with the ScrollView CSS out-of-the-box. It has been removed as of the 3.3.0 release, since it makes it harder for developers to nest lists inside the ScrollView content, and in general, ScrollView is content agnostic.</p>

<h3>Preventing Native Behavior For Content</h3>

<p>In this example, since we have images which act as drag/flick targets, we need to stop the default image drag/drop behavior in certain browsers (for example gecko and IE), by preventing default on the underlying mousedown event. If we don't prevent default, the image will be natively draggable by default, and interfere with scrolling:</p>

<pre class="code prettyprint">&#x2F;&#x2F; Prevent the image from being natively dragged
content.delegate(&quot;mousedown&quot;, function(e) {
    e.preventDefault();
}, &quot;img&quot;);</pre>


<h2>Complete Example Source</h2>
<pre class="code prettyprint">&lt;div id=&quot;scrollview-container&quot;&gt;
    &lt;div id=&quot;scrollview-header&quot;&gt;
        &lt;h1&gt;Horizontal ScrollView&lt;&#x2F;h1&gt;
    &lt;&#x2F;div&gt;
    
    &lt;div id=&quot;scrollview-content&quot; class=&quot;yui3-scrollview-loading&quot;&gt;
        &lt;ul&gt;
            &lt;li&gt;&lt;img src=&quot;http:&#x2F;&#x2F;farm5.static.flickr.com&#x2F;4136&#x2F;4802088086_c621e0b501.jpg&quot; alt=&quot;Above The City II&quot;&gt;&lt;&#x2F;li&gt;
            &lt;li&gt;&lt;img src=&quot;http:&#x2F;&#x2F;farm5.static.flickr.com&#x2F;4114&#x2F;4801461321_1373a0ef89.jpg&quot; alt=&quot;Walls and Canyon&quot;&gt;&lt;&#x2F;li&gt;
            &lt;li&gt;&lt;img src=&quot;http:&#x2F;&#x2F;farm5.static.flickr.com&#x2F;4100&#x2F;4801614015_4303e8eaea.jpg&quot; alt=&quot;Stairs Using In Situ Stone&quot;&gt;&lt;&#x2F;li&gt;
            &lt;li&gt;&lt;img src=&quot;http:&#x2F;&#x2F;farm5.static.flickr.com&#x2F;4076&#x2F;4801368583_854e8c0ef3.jpg&quot; alt=&quot;Tree Silhouette&quot;&gt;&lt;&#x2F;li&gt;
        &lt;&#x2F;ul&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;

&lt;div id=&quot;additional-content&quot;&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras aliquam hendrerit elit id vulputate. Pellentesque pellentesque erat rutrum velit facilisis sodales convallis tellus lacinia. Curabitur gravida mi sit amet nulla suscipit sed congue dolor volutpat. Aenean sem tortor, pretium et euismod in, imperdiet sit amet urna. Ut ante nisi, auctor mattis suscipit a, ullamcorper eget leo. Phasellus sagittis ante at lectus rutrum ut sollicitudin sem malesuada. Duis ultrices sapien et nulla tincidunt malesuada. Mauris ante turpis, dignissim eu tincidunt vitae, placerat quis diam. In augue nisl, cursus at rutrum ut, scelerisque et erat. Suspendisse potenti. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris orci dui, aliquam ut convallis ut, dapibus et erat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Mauris placerat elit id lectus rhoncus in dignissim justo mollis. Donec nec odio sapien. In iaculis euismod felis non laoreet. Mauris ornare varius neque, et congue erat porta a. Aliquam nec auctor lectus. Etiam ut ipsum a nibh iaculis fringilla.&lt;&#x2F;p&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras aliquam hendrerit elit id vulputate. Pellentesque pellentesque erat rutrum velit facilisis sodales convallis tellus lacinia. Curabitur gravida mi sit amet nulla suscipit sed congue dolor volutpat. Aenean sem tortor, pretium et euismod in, imperdiet sit amet urna. Ut ante nisi, auctor mattis suscipit a, ullamcorper eget leo. Phasellus sagittis ante at lectus rutrum ut sollicitudin sem malesuada. Duis ultrices sapien et nulla tincidunt malesuada. Mauris ante turpis, dignissim eu tincidunt vitae, placerat quis diam. In augue nisl, cursus at rutrum ut, scelerisque et erat. Suspendisse potenti. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris orci dui, aliquam ut convallis ut, dapibus et erat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Mauris placerat elit id lectus rhoncus in dignissim justo mollis. Donec nec odio sapien. In iaculis euismod felis non laoreet. Mauris ornare varius neque, et congue erat porta a. Aliquam nec auctor lectus. Etiam ut ipsum a nibh iaculis fringilla.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;

&lt;script type=&quot;text&#x2F;javascript&quot; charset=&quot;utf-8&quot;&gt;
YUI().use(&#x27;scrollview&#x27;, function(Y) {

    var scrollView = new Y.ScrollView({
        id: &#x27;scrollview&#x27;,
        srcNode: &#x27;#scrollview-content&#x27;,
        width: 320,
        flick: {
            minDistance:10,
            minVelocity:0.3,
            axis: &quot;x&quot;
        }
    });

    scrollView.render();

    &#x2F;&#x2F; Prevent default image drag behavior
    scrollView.get(&quot;contentBox&quot;).delegate(&quot;mousedown&quot;, function(e) {
        e.preventDefault();
    }, &quot;img&quot;);
    
});
&lt;&#x2F;script&gt;</pre>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="This example creates a basic ScrollView which doesn&#x27;t include a scrollbar indicator.">
                                        <a href="scrollview-base.html">Basic ScrollView Without a Scroll Indicator</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows the classic Scrollview implementation, including scroll indicators (bars) and including code to suppress link navigation while scrolling.">
                                        <a href="scrollview.html">ScrollView with Scroll Indicator and Link Suppression Behavior</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example creates a horizontal ScrollView.">
                                        <a href="scrollview-horiz.html">Horizontal ScrollView</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example creates a horizontal ScrollView with pagination support.">
                                        <a href="scrollview-paging.html">ScrollView With Pagination</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            

            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
